home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Simulation / PDP-8 Simulator / Source Code / Assembler / Code.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-13  |  7.5 KB  |  351 lines  |  [TEXT/KAHL]

  1. /************************************************************
  2. *
  3. *
  4. *    Unit containing instruction code.
  5. *
  6. *    by Adrian Bool in cooperation with Graham Cox.
  7. *
  8. *    copyright © phantasm coding 1992.
  9. *
  10. *
  11. ************************************************************/
  12.  
  13. #include "Global.h"
  14. #include "Code.h"
  15.  
  16. #include "Code.proto.h"
  17.  
  18. /* memory referance instructions */
  19.  
  20. void assembleOpcode(opcode opCode,short pass,rBlock theDestination,short *size,pHandle theProgram)
  21.     {
  22.     (pdp8[opCode]).itsFunction(pass,theDestination,size,theProgram);
  23.     }
  24.     
  25.     
  26. void cmpAND(short pass,rBlock data,short *size,pHandle theProgram)
  27.     { /* ANDs the ACC with amemory location */
  28.     *size=1;
  29.     if (pass == 1) 
  30.         {
  31.         str255 dummy;
  32.         *size = 1;
  33.         getSection(theProgram,dummy);
  34.         }
  35.     if (pass == 2)
  36.         {
  37.         makeMemoryInstruction(and,data,theProgram);
  38.         }
  39.     }
  40.             
  41. void cmpTAD(short pass,rBlock data,short *size,pHandle theProgram)
  42.     {    /* adds a memory location to the ACC */
  43.     *size = 1;
  44.     if (pass == 1) 
  45.         {
  46.         str255 dummy;
  47.         getSection(theProgram,dummy);
  48.         }
  49.     if (pass == 2)
  50.         {
  51.         makeMemoryInstruction(tad,data,theProgram);
  52.         }
  53.     }
  54.             
  55. void cmpISZ(short pass,rBlock data,short *size,pHandle theProgram)
  56.     {    /* increments memory location then skips if result = 0 */
  57.     *size = 1;
  58.     if (pass == 1) 
  59.         {
  60.         str255 dummy;
  61.         getSection(theProgram,dummy);
  62.         }
  63.     if (pass == 2)
  64.         {
  65.         makeMemoryInstruction(isz,data,theProgram);
  66.         }
  67.     }
  68.             
  69. void cmpDCA(short pass,rBlock data,short *size,pHandle theProgram)
  70.     {    /* deposit ACC in memory then set ACC to 0 */
  71.     *size = 1;
  72.     if (pass == 1) 
  73.         {
  74.         str255 dummy;
  75.         getSection(theProgram,dummy);
  76.         }
  77.     if (pass == 2)
  78.         {
  79.         makeMemoryInstruction(dca,data,theProgram);
  80.         }
  81.     }
  82.             
  83. void cmpJMS(short pass,rBlock data,short *size,pHandle theProgram)
  84.     {    /* jump to subroutine */
  85.     *size = 1;
  86.     if (pass == 1) 
  87.         {
  88.         str255 dummy;
  89.         getSection(theProgram,dummy);
  90.         }
  91.     if (pass == 2)
  92.         {
  93.         makeMemoryInstruction(jms,data,theProgram);
  94.         }
  95.     }
  96.     
  97. void cmpJMP(short pass,rBlock data,short *size,pHandle theProgram)
  98.     {    /* jump to address */
  99.     *size=1;
  100.     if (pass == 1) 
  101.         {
  102.         str255 dummy;
  103.         getSection(theProgram,dummy);
  104.         }
  105.     if (pass == 2)
  106.         {
  107.         makeMemoryInstruction(jmp,data,theProgram);
  108.         }
  109.     }
  110.             
  111. void cmpIO(short pass,rBlock data,short *size,pHandle theProgram)
  112.     {    /* input/output instruction */
  113.     *size = 1;
  114.     if (pass == 1) 
  115.         {
  116.         str255 dummy;
  117.         getSection(theProgram,dummy);                
  118.         }
  119.     if (pass == 2)
  120.         {
  121.         str255 theOperand;
  122.         wordType theAddress;
  123.         
  124.         getSection(theProgram,theOperand);
  125.         theAddress = evaluateValue(theProgram,theOperand);
  126.         data[0] = pdp8[io].iNumber << 9;
  127.         data[0] |= (theAddress & 63) << 3;
  128.         }
  129.     }
  130.             
  131. /* accumulator instructions : group one */
  132.         
  133. void cmpCLL(short pass,rBlock data,short *size,pHandle theProgram)        
  134.     {    /* clear link */
  135.     *size = 1;
  136.     if (pass == 2) data[0] = pdp8[cll].iNumber;
  137.     }
  138.             
  139. void cmpCMA(short pass,rBlock data,short *size,pHandle theProgram)                 
  140.     {    /* complement accumulator */
  141.     *size = 1;
  142.     if (pass == 2) data[0] = pdp8[cma].iNumber;
  143.     }
  144.             
  145. void cmpCML(short pass,rBlock data,short *size,pHandle theProgram)
  146.     {    /* complement link */
  147.     *size = 1;
  148.     if (pass == 2) data[0] = pdp8[cml].iNumber;
  149.     }
  150.             
  151. void cmpIAC(short pass,rBlock data,short *size,pHandle theProgram)
  152.     {    /* increment accumulator */
  153.     *size = 1;
  154.     if (pass == 2) data[0] = pdp8[iac].iNumber;
  155.     }
  156.  
  157. void cmpRAR(short pass,rBlock data,short *size,pHandle theProgram)
  158.     {    /* rotate accumulator one position right */
  159.     *size = 1;
  160.     if (pass == 2) data[0] = pdp8[rar].iNumber;
  161.     }
  162.     
  163. void cmpRAL(short pass,rBlock data,short *size,pHandle theProgram)
  164.     {    /* rotate accumulator one position left */
  165.     *size = 1;
  166.     if (pass == 2) data[0] = pdp8[ral].iNumber;
  167.     }
  168.     
  169. void cmpRTR(short pass,rBlock data,short *size,pHandle theProgram)
  170.     {    /* rotate accumulator two positions right */
  171.     *size = 1;
  172.     if (pass == 2) data[0] = pdp8[rtr].iNumber;
  173.     }
  174.     
  175. void cmpRTL(short pass,rBlock data,short *size,pHandle theProgram)
  176.     {    /* rotate accumulator two positions left */
  177.     *size = 1;
  178.     if (pass == 2) data[0] = pdp8[rtl].iNumber;
  179.     }
  180.     
  181. void cmpNOP(short pass,rBlock data,short *size,pHandle theProgram)
  182.     {    /* no operation */
  183.     *size = 1;
  184.     if (pass == 2) data[0] = pdp8[nop].iNumber;
  185.     }
  186.     
  187. /* accumulator instuctions : group 2 */
  188.                     
  189. void cmpSMA(short pass,rBlock data,short *size,pHandle theProgram)        
  190.     {    /* skip on minus accumulator */
  191.     *size = 1;
  192.     if (pass == 2) data[0] = pdp8[sma].iNumber;
  193.     }
  194.             
  195. void cmpSZA(short pass,rBlock data,short *size,pHandle theProgram)
  196.     {    /* skip on zero link */
  197.     *size = 1;
  198.     if (pass == 2) data[0] = pdp8[sza].iNumber;
  199.     }
  200.     
  201. void cmpSNL(short pass,rBlock data,short *size,pHandle theProgram)        
  202.     {    /* skip on non-zero link */
  203.     *size = 1;
  204.     if (pass == 2) data[0] = pdp8[snl].iNumber;
  205.     }
  206.     
  207. void cmpSPA(short pass,rBlock data,short *size,pHandle theProgram)        
  208.     {    /* skip on positive accumulator */
  209.     *size = 1;
  210.     if (pass == 2) data[0] = pdp8[spa].iNumber;
  211.     }
  212.     
  213. void cmpSNA(short pass,rBlock data,short *size,pHandle theProgram)        
  214.     {    /* skip on non-zero accumulator */
  215.     *size = 1;
  216.     if (pass == 2) data[0] = pdp8[sna].iNumber;
  217.     }
  218.     
  219. void cmpSZL(short pass,rBlock data,short *size,pHandle theProgram)        
  220.     {    /* skip on zero link */
  221.     *size = 1;
  222.     if (pass == 2) data[0] = pdp8[szl].iNumber;
  223.     }
  224.     
  225. void cmpCLA(short pass,rBlock data,short *size,pHandle theProgram)        
  226.     {    /* clear accumulator */
  227.     *size = 1;
  228.     if (pass == 2) data[0] = pdp8[cla].iNumber;
  229.     }
  230.             
  231. void cmpOSR(short pass,rBlock data,short *size,pHandle theProgram)
  232.     {    /* or switches in accumulator */
  233.     /* not implementated */
  234.     AsmError = OSRNotImplemented;
  235.     }
  236.             
  237. void cmpHLT(short pass,rBlock data,short *size,pHandle theProgram)
  238.     {    /* Halt proccessor */
  239.     *size = 1;
  240.     if (pass == 2) data[0] = pdp8[hlt].iNumber;
  241.     }
  242.  
  243. /* pseudo operations */
  244.             
  245. void cmpORG(short pass,rBlock data,short *size,pHandle theProgram)        
  246.     {    /* set start address of code */
  247.     *size = 0;
  248.     if (pass == 1) 
  249.         {
  250.         str255 startAddress;
  251.         addressType theAddress;
  252.                 
  253.         getSection(theProgram,startAddress);
  254.         theAddress = evaluateAddress(theProgram, startAddress);
  255.         
  256.         if (!AsmError)
  257.             {
  258.             (*(*theProgram)->objectCode)->startAddress = theAddress;
  259.             (*(*theProgram)->objectCode)->address = theAddress;    
  260.             }
  261.         }
  262.     if (pass == 2)
  263.         {
  264.         str255 dummy;
  265.         
  266.         getSection(theProgram,dummy);
  267.         }
  268.     }
  269.             
  270. void cmpEQU(short pass,rBlock data,short *size,pHandle theProgram)
  271.     {    /* equate symbol to value */
  272.     *size = 0;
  273.     if (pass == 1)
  274.         {
  275.         str255 theLabel;
  276.         str255 theValue;
  277.         
  278.         biggestType aValue;
  279.         
  280.         getSection(theProgram,theLabel);
  281.         getSection(theProgram,theValue);
  282.         
  283.         aValue = evaluateValue(theProgram,theValue);
  284.         
  285.         if (!AsmError)
  286.             newLabel(theProgram,theLabel,aValue);
  287.         }
  288.     if (pass == 2)
  289.         {
  290.         str255 dummy;
  291.         
  292.         getSection(theProgram,dummy);
  293.         getSection(theProgram,dummy);
  294.         }
  295.     }
  296.             
  297. void cmpEND(short pass,rBlock data,short *size,pHandle theProgram)
  298.     {    /* signify physical end of source code */
  299.     *size = 0;
  300.     }
  301.             
  302. void cmpDATA(short pass,rBlock returnData,short *size,pHandle theProgram)
  303.     {    /* allocate values to memory locations */
  304.     str255 theData;
  305.     str255 aData;
  306.     short position;
  307.     wordType theValue;    
  308.     
  309.     *size = 0;
  310.     position = 0;
  311.     theValue = 0;
  312.  
  313.     getSection(theProgram,theData);
  314.     
  315.     while (getSegment(theData,&position,aData) && (!AsmError))
  316.         {
  317.         if (pass == 2)
  318.             {
  319.             theValue = evaluateValue(theProgram,aData);
  320.             if(!AsmError)
  321.                 returnData[*size] = theValue;
  322.             }
  323.         (*size)++;
  324.         }
  325.     }
  326.             
  327. void cmpSTORE(short pass,rBlock data,short *size,pHandle theProgram)    
  328.     {    /* allocate a number of words in memory */
  329.     short x,noOfWords;
  330.     str255 request;
  331.     
  332.     getSection(theProgram,request);
  333.     noOfWords = evaluateValue(theProgram,request);
  334.     
  335.     if(!AsmError)
  336.         {
  337.         for(x = 0 ; x < noOfWords ; x++) data[x] = 0;
  338.         *size = noOfWords;
  339.         }
  340.     }
  341.     
  342.             
  343.         
  344.         
  345.         
  346.         
  347.         
  348.         
  349.         
  350.         
  351.